DECLARE
    @returnXml XML
,   @branch1   XML
,   @branch2   XML

SET @branch1 = 
(
    SELECT
        SegmentBranch = CAST(dbo.fGetWebXmlString('SegmentBranch',SegmentId) AS xml)
    FROM
        SegmentDocument AS Branch
    WHERE
        DocumentId = @DocumentId
    FOR XML AUTO, ELEMENTS, TYPE
)

SET @branch2 = 
(
    SELECT
        SegmentBranch = CAST(dbo.fGetWebXmlString('SegmentBranch',SegmentId) AS xml)
    FROM
        [Document] AS Branch
    WHERE
        DocumentId = @DocumentId
    FOR XML AUTO, ELEMENTS, TYPE
)

SET @returnXml = 
(
    SELECT
        @branch1 "node()"
    ,   @branch2 "node()"
    FOR XML PATH('Branches')
)

SELECT @returnXml